<?php
/**
 * 分类相关通用方法
 *
 * Author:李强 EdwinLee
 * Company:上海煦鸣网络科技有限公司
 * Time: 2018-01-10 21:25
 */

namespace App\Traits;

use App\Services\Service\DataService;
use Illuminate\Support\Facades\Cache;
use Mockery\Matcher\Closure;

trait Category
{
    /**
     * 根据获取分类列表
     *
     * @param string $type
     * @param int $pid
     * @return mixed
     */
    public static function getChildList($type = 'article', $pid = 0)
    {
        $categorys = self::where(['type' => $type, 'status' => 1])->get();
        $datas = DataService::channelLevel($categorys, $pid, "", 'id', 'parent_id');
        return $datas;
    }

    /**
     * 获取上级信息
     *
     * @return bool
     */
    public function parent()
    {
        $parent = self::find($this->parent_id);
        return is_null($parent) ? false : $parent;
    }
}